import { Injectable } from '@angular/core';
import { HttpClient } from '../../../providers/httpClient';
import { Config } from '../../../providers/config';
import { Common } from "../../../providers/common";
import _ from "lodash";

@Injectable()
export class CoinService {
	constructor(
		public httpClient: HttpClient,
		public config: Config,
    public common: Common
	) { }

  testFTS_001_0010() {
    let postBody = {
      "module": "OAServer",
      "method": "testFTS_001_0010",
      "params": {

      }
    };

    return this.httpClient.post(postBody, {
      isShowLoading: false
    });
  }

  getCoinTrialCalculationResult(condition) {
	  let postBody = {
      "module": "OAServer",
      "method": "getCoinTrialCalculationResult",
      "params": {
        "fund_code": condition.fund_code,
        "l_begin_date": _.replace(condition.l_begin_date, /-/g, ""),
        "l_fut_days": condition.l_fut_days,
        "l_his_days": condition.l_his_days,
        "simulatedScene": condition.simulatedScene
      }
    };

	  console.log(postBody);
	  return this.httpClient.post(postBody, {
	    isShowLoading: true
    });
  }

  getSimulatedScene() {
    let postBody = {
      "module": "OAServer",
      "method": "getSimulatedScene",
      "params": {

      }
    };
    return this.httpClient.post(postBody, {
      isShowLoading: true
    });
  }

  /**
   * 保存模拟情景
   * @param user
   * @param scene_name
   * @returns {any}
   */
  saveSimulatedScene(user, scene_name) {
	  let postBody = {
	    "module": "KSB",
      "method": "IPM_003_0010",
      "format": "json",
      "params": {
	      "vc_plan_name": scene_name,
        "vc_user": user.loginid,
        "l_create_date": _.replace(this.common.getNowFormatDate(), /-/g, "")
      }
    };

	  return this.httpClient.post(postBody, {
	    isShowLoading: true
    });
  }

  /**
   * 保存模拟情景
   * @param user
   * @param scene_name
   * @returns {any}
   */
  deleteSimulatedScene(l_plan_no) {
    let postBody = {
      "module": "KSB",
      "method": "IPM_003_0080",
      "format": "json",
      "params": {
        "l_plan_no": l_plan_no
      }
    };

    return this.httpClient.post(postBody, {
      isShowLoading: true
    });
  }

  /**
   * 删除方案
   * @param l_plan_no
   * @returns {any}
   */
  deleteSimulatedScenePlan(l_serial_no) {
    let postBody = {
      "module": "KSB",
      "method": "IPM_003_0050",
      "format": "json",
      "params": {
        "l_serial_no": l_serial_no
      }
    };

    return this.httpClient.post(postBody, {
      isShowLoading: true,
      isAlterError: false
    });
  }

  /**
   * 获取模拟方案相关的字典数据
   * @returns {any}
   */
  getPlanDic(fundCode) {
    let postBody = {
      "module": "OAServer",
      "method": "getPlanDic",
      "params": {
        "fundCode": fundCode
      }
    };

    return this.httpClient.post(postBody, {
      isShowLoading: true
    });
  }

  /**
   * 获取债券代码
   * @param keyWord
   * @param page
   * @returns {any}
   */
  getStockNoList(marketNo, stockClass, keyWord, page) {
    let postBody = {
      "module": "OAServer",
      "method": "getStockNoList",
      "params": {
        "marketNo": marketNo,
        "stockClass": stockClass,
        "keyWord": keyWord,
        "page": page,
        "pageSize": this.config.pageSize
      }
    };

    return this.httpClient.post(postBody, {
      isShowLoading: true
    });
  }

  /**
   * 获取净价、全价、收益率
   * @param params
   * @returns {any}
   */
  getStockPrice(params) {
    let postBody = {
      "module": "OAServer",
      "method": "getStockPrice",
      "params": {
        "fundCode": params["fundCode"],
        "selectedRadio": params["selectedRadio"],
        "l_date": _.replace(params["l_date"], /-/g, ""),
        "vc_stock_no": params["vc_stock_no"],
        "en_net_price": params["en_net_price"],
        "en_full_price": params["en_full_price"],
        "en_yield": params["en_yield"],
        "l_clear_speed": params["l_clear_speed"]
      }
    };

    return this.httpClient.post(postBody, {
      isShowLoading: false
    });
  }

  /**
   * 保存试算方案
   * @param params
   * @returns {any}
   */
  savePlan(params) {
    let postBody = {
      "module": "KSB",
      "method": "IPM_003_0030",
      "format": "json",
      "params": params
    };
    return this.httpClient.post(postBody, {
      isShowLoading: false
    });
  }

  /**
   * 根据回购利率计算收益
   * @param params
   */
  getHGPrice(params) {
    let postBody = {
      "module": "KSB",
      "method": "IPM_002_0060",
      "format": "json",
      "params": params
    };
    return this.httpClient.post(postBody, {
      isShowLoading: false,
      isAlterError: false
    });
  }

  /**
   * 获取手续费
   * @param params
   * @returns {any}
   */
  getPoundageFee(params) {
    let postBody = {
      "module": "OAServer",
      "method": "getPoundageFee",
      "params": params
    };

    return this.httpClient.post(postBody, {
      isShowLoading: false,
      isAlterError: false
    });
  }

  /**
   * 获取存款行信息
   * @param params
   * @returns {any}
   */
  getDeposit(keyWord, page) {
    let postBody = {
      "module": "OAServer",
      "method": "getDepositList",
      "format": "json",
      "params": {
          "keyWord": keyWord,
          "page": page,
          "pageSize": this.config.pageSize
      }
    };
    return this.httpClient.post(postBody, {
      isShowLoading: true
    })
  }

  /**
   * 获取存款列表
   * @param fundNo
   */
  getDepositMoney(fundCode) {
    let postBody = {
      "module": "OAServer",
      "method": "getDepositMoneyList",
      "params": {
        "fundCode": fundCode
      }
    };
    console.log("getDepositMoney().postBody", postBody);
    return this.httpClient.post(postBody, {
      isShowLoading: true
    })
  }

  /**
   * 获取自定义列
   * @returns {any}
   */
  getCoinColumns() {
    let postBody = {
      "module": "OAServer",
      "method": "getCoinColumns",
      "params":{
      }
    };
    return this.httpClient.post(postBody, {
      isShowLoading: false
    })
  }

  postTRA_002_0051(params) {
    let postBody = {
      "module": "KSB",
      "method": "TRA_002_0051",
      "format": "json",
      "params": {
        "l_date": params["l_date"],
        "l_day": params["l_day"],
        "c_date_type": "1"
      }
    };
    return this.httpClient.post(postBody, {
      isShowLoading: false
    })
  }

  getCoinTrialResult(condition) {
	  let postBody = {
      "module": "OAServer",
      "method": "getCoinTrialResult",
      "params": {
        "fund_code": condition.fund_code,
        "l_begin_date": _.replace(condition.l_begin_date, /-/g, ""),
        "l_fut_days": condition.l_fut_days,
        "l_his_days": condition.l_his_days,
        "simulatedScene": condition.simulatedScene
      }
    };

	  console.log(postBody);
	  return this.httpClient.post(postBody, {
	    isShowLoading: false
    });
  }

  getCoinCaculateDatas(condition) {
	  let postBody = {
      "module": "OAServer",
      "method": "getCoinCaculateDatas",
      "params": {
        "fund_code": condition.fund_code,
        "l_begin_date": _.replace(condition.l_begin_date, /-/g, ""),
        "l_fut_days": condition.l_fut_days,
        "l_his_days": condition.l_his_days,
        "simulatedScene": condition.simulatedScene
      }
    };

	  console.log(postBody);
	  return this.httpClient.post(postBody, {
	    isShowLoading: false
    });
  }

  getStructuredFundTrialDatas(condition) {
    let postBody = {
      "module": "OAServer",
      "method": "getStructuredFundTrialDatas",
      "params": {
        "fund_code": condition.fund_code,
        "l_begin_date": _.replace(condition.l_begin_date, /-/g, ""),
        "l_fut_days": condition.l_fut_days,
        "l_his_days": condition.l_his_days,
        "simulatedScene": condition.simulatedScene
      }
    };

	  console.log(postBody);
	  return this.httpClient.post(postBody, {
	    isShowLoading: false
    });
  }

  getSimulatedSceneDatas(condition) {
    let postBody = {
      "module": "OAServer",
      "method": "getSimulatedSceneDatas",
      "params": {
        "fund_code": condition.fund_code,
        "l_begin_date": _.replace(condition.l_begin_date, /-/g, ""),
        "l_fut_days": condition.l_fut_days,
        "l_his_days": condition.l_his_days,
        "simulatedScene": condition.simulatedScene
      }
    };

	  console.log(postBody);
	  return this.httpClient.post(postBody, {
	    isShowLoading: false
    });
  }

  getPositionTrialDatas(condition) {
    let postBody = {
      "module": "OAServer",
      "method": "getPositionTrialDatas",
      "params": {
        "fund_code": condition.fund_code,
        "l_begin_date": _.replace(condition.l_begin_date, /-/g, ""),
        "l_fut_days": condition.l_fut_days,
        "l_his_days": condition.l_his_days,
        "simulatedScene": condition.simulatedScene
      }
    };

	  console.log(postBody);
	  return this.httpClient.post(postBody, {
	    isShowLoading: false
    });
  }
}
